package com.source.hotelbath.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.source.hotelbath.R;


/**
 * Toast工具类
 */
public class ToastUtils {

    private static Toast mToast; //toast

    /**
     * 显示系统的Toast
     */
    public static void showSystemToast(Context context, CharSequence text) {
        Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
    }

    /**
     * 自定义的Toast
     */
    public static void showToast(Context context, String text) {
        View view = View.inflate(context, R.layout.item_toast, null);
        TextView tv = (TextView) view.findViewById(R.id.tv_toast);
        tv.setText(text);
        if (mToast == null) {
            mToast = new Toast(context);
        }
        mToast.setDuration(Toast.LENGTH_SHORT);
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.setView(view);
        mToast.show();

    }

    public static void cancelToast() {
        if (mToast != null) {
            mToast.cancel();
        }
    }
}
